﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Windows.Navigation;

namespace OttawaTourMap
{
    public partial class TourDetailsPage : PhoneApplicationPage
    {
        public string tourID { get; private set; }

        public TourDetailsPage()
        {
            tourID = null;
            InitializeComponent();
        }

        // When page is navigated to set data context to selected item in list
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            string s = "";
            if (NavigationContext.QueryString.TryGetValue("tourIndex", out s))
            {
                tourID = s;
                var tours = (Expression.Blend.SampleData.ottawaSampleDataSource.toursList)App.Current.Resources["OttawaSampleDataSource"];
                //Get the selected tour inforamtion from the id
                //Iterate through the collection
                Expression.Blend.SampleData.ottawaSampleDataSource.tour selectedTour = null;
                foreach (var tour in tours.tourCollection)
                {
                    if (tour.id.Equals(tourID))
                    {
                        selectedTour = tour;
                        break;
                    }
                }

                if(selectedTour != null)
                DataContext = selectedTour;
            }
        }

       
        private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
        {
            //Navigate to details page and inform the selection
            NavigationService.Navigate(new Uri("/MainPage.xaml?tourIndex=" + tourID, UriKind.Relative));
        }
    }
}